﻿
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using Abp;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.AutoMapper;
using Abp.Configuration;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Linq.Extensions;
using KDS.Mes.Mes.Colors.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.Colors
{
    /// <summary>
    /// 颜色信息的导出EXCEL功能的实现
    /// </summary>
    public class ColorListExcelExporter : EpPlusExcelExporterBase, IColorListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public ColorListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出颜色信息到EXCEL文件
        /// <param name="colorListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportColorToFile(List<ColorListDto> colorListDtos){


var file=CreateExcelPackage("colorList.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("Color"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("ColorName"),  
     L("ColorCode"),  
     L("LastModificationTime"),  
     L("CreationTime")  
                        );
         AddObjects(sheet,2,colorListDtos,
            
      _ => _.ColorName,   
       
      _ => _.ColorCode,   
       
 _ =>_timeZoneConverter.Convert( _.LastModificationTime,_abpSession.TenantId, _abpSession.GetUserId()),          
 _ =>_timeZoneConverter.Convert( _.CreationTime,_abpSession.TenantId, _abpSession.GetUserId())  
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 4; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
